<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>用户管理</title>
	<%@ include file="/view/common/tags.jsp"%>
	<script type="text/javascript" src="${sysManagerV1}/js/My97DatePicker/WdatePicker.js"> </script>
</head>
<body>
<!-- Main content -->
<section class="content"> 
        <div class="row">
            <div class="col-md-12">
                <!-- BEGIN SAMPLE TABLE PORTLET-->
                <div class="box">
                    <div class="box-body">
                       <div class="panel panel-default">
                            <div class="panel-body" style="padding-bottom:5px;">
                                <form class="form-horizontal" action="${sysManagerV1 }/loginlog/" method="post" id="dataForm">
                                <input id="roleNameList" type="hidden" value="${roleNameList}" >
                                      <div class="searchMenu">
	                                        <div style="margin-left:10px;">
	                                        	<sk:button type="button" rightKey="20170805134951" _class="btn btn-success btn-sm" onclick="add()"><span class='glyphicon glyphicon-plus'></span>添&nbsp;加</sk:button>
	                                        	<sk:button type="button" rightKey="20170805134951" _class="btn btn-warning btn-sm" onclick="refreshRouter()"><span class='glyphicon glyphicon-import'></span>刷&nbsp;新</sk:button>
	                                        </div>
                                       </div>
                                </form>
                            </div>
                        </div>
                        
                        <table class="table table-hover table-condensed table-bordered table-striped" id="dataTable" >
                            <thead>
                                <tr>
                                	<th data-field="index" data-align="center" data-formatter="indexFormatter" data-sortable="false">序号</th>
                                    <th data-field="path" data-align="center" data-sortable="true">映射路径</th>
                                    <th data-field="serviceId" data-align="center" data-sortable="true">服务ID</th>
                                    <th data-field="url" data-align="center"   data-sortable="true">url映射</th>
                                    <th data-field="stripPrefix" data-align="center" data-formatter="stripPrefixFormatter" data-sortable="true">是否去掉前缀</th>
                                    <th data-field="retryable" data-align="center" data-formatter="retryableFormatter" data-sortable="true">是否重试</th>
                                    <th data-field="updateTime" data-align="center" data-formatter="timeFormatter_point" data-sortable="true">更新时间</th>
                                    <th data-field="deleteButton" data-align="center"  data-formatter="buttonFormatter" data-sortable="false">操作</th>
                                </tr>
                            </thead>
                        </table>

                    </div>
                </div>
            </div>
            <!-- END SAMPLE TABLE PORTLET-->
            </div>
        </div>
</section>
<%@ include file="/view/common/footer.jsp"%>
</body>
<script type="text/javascript">
// 提示信息
var msgg='<%=request.getAttribute("msg")%>';
if( msgg && msgg!=null && msgg!='null'){ 
	  layer.info(msgg, {icon: 1});
}

//加载table 数据
$(function(){
    $("#dataTable").bootstrapTable({ 
        url: "${sysManagerV1}/router/data.json",
        method:"get", 
        pagination:true,
        sidePagination:"server",
        queryParams: function(params) {
            return $.extend({}, params, parseJson(decodeURIComponent($("#dataForm").serialize())));     
        }
   }); 
}) 

//查询
function findData(){
   $("#dataTable").bootstrapTable("refresh",{} ); 
}

/*bootstrap table点击行事件*/
$(function(){
     $("body").on("click","table>tbody>tr",function(){
      $(this).css("background","#e1ecf1").siblings().css("background","");
   });
})

// 发布状态
function stripPrefixFormatter(value, row) {
    var html = "";
    if (row.stripPrefix == 0) {
        html = "<span class='text-success'>是 </span>&nbsp;&nbsp;&nbsp;&nbsp;";
    }else {
        html = "<span class='text-warning'>否 </span>&nbsp;&nbsp;&nbsp;&nbsp;";
    }
    return html;
}

// 发布状态
function retryableFormatter(value, row) {
    var html = "";
    if (row.retryable == 0) {
        html = "<span class='text-success'>是 </span>&nbsp;&nbsp;&nbsp;&nbsp;";
    }else {
        html = "<span class='text-warning'>否 </span>&nbsp;&nbsp;&nbsp;&nbsp;";
    }
    return html;
}

//操作按钮
function buttonFormatter(value, row, index) {
    var caozuo3 = "<button id='btn_delete' type='button' onclick='deleteEmp("+row.rowId+");'  class='btn btn-default btn-sm'><span class='glyphicon glyphicon-remove'></span>&nbsp;删&nbsp;除&nbsp;</button>";
    var caozuo2 = "<button id='btn_edit' type='button' onclick='_update("+row.rowId + ", \"" + row.path + "\", \"" + row.serviceId + "\", \"" + row.stripPrefix + "\", \"" + row.retryable + "\");'  class='btn btn-default btn-sm'><span class='glyphicon glyphicon-pencil'></span>修 改</button>";
    return caozuo2 + caozuo3;
}

//弹出添加的窗口
function add(){
 tableIndex = layer.open({
     type: 2,
     title: "添加焦点图",
     closeBtn: 1,
     shadeClose: true,
     area: ['630px', '270px'],
     content: "${sysManagerV1}/systemRouter/toAddRouter?rowId=0&stripPrefix=1&retryable=1",
     btn: ["确 认","关 闭"], 
     yes: function(index, layero){
         var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：
         iframeWin.add();
     }
 });
}

//弹出添加的窗口      修改功能
function _update(rowId, path, serviceId, stripPrefix, retryable){
	var param = "?rowId=" + rowId + "&path=" + path + "&serviceId=" + serviceId + "&stripPrefix=" + stripPrefix + "&retryable=" + retryable;
    tableIndex = layer.open({
        type: 2,
        title: "修改焦点图",
        closeBtn: 1,
        shadeClose: true,
        area: ['630px', '270px'],
        content: "${sysManagerV1}/systemRouter/toAddRouter" + param,
        btn: ["确 认","关 闭"], 
        yes: function(index, layero){
            var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：
            iframeWin.add();
        }
    });
}

//删除路由
function deleteEmp(rowId){
    layer.confirm("您确认【删除】?", {btn: ['确认', '取消']},
        function(){
            $.ajax({
                url: "${routerRemove}",
                type: "post",
                cache: false,
                data: {id:rowId},
                dataType:"json",
                async:false,
                success: function(data) {
                    if (data.code == 0) { 
                        layer.msg("删除成功", {icon: 1});
                        findData();
                    } else {
                        layer.msg(data.message, {icon: 5});
                    }
                }
           });
    });
}

//刷新路由
function refreshRouter(){
	$.ajax({
        url: "${routerRefresh}",
        type: "post",
        cache: false,
        dataType:"json",
        async:false,
        success: function(data) {
            if (data.code == 0) { 
                layer.msg("刷新成功", {icon: 1});
                findData();
            } else {
                layer.msg(data.message, {icon: 5});
            }
        }
    });
}
</script>
</html>